from rest_framework import serializers

from api.conf import order_status
from app.models import Order
from app.models.pay_method import PayMethod


class PaySerializer(serializers.Serializer):
    order = serializers.PrimaryKeyRelatedField(queryset=Order.objects.all())
    pay_method = serializers.PrimaryKeyRelatedField(queryset=PayMethod.objects.all())
    pay_result = serializers.IntegerField(required=False)

    def validate_order(self, order):
        if order.status != order_status.NOT_PAYED:
            raise serializers.ValidationError(detail=u'订单状态异常')
        return order
